//
//  DescVedioViewController.m
//  XiaoHongShu
//
//  Created by Jason on 2022/7/2.
//

#import "DescVideoViewController.h"
#import "MainDataModel.h"
#import "DescVideoCell.h"
#import <AVFoundation/AVFoundation.h>

@interface DescVideoViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, DescVideoCelllDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;

@end

static NSString *const vedioCell = @"cell_vedio";

@implementation DescVideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"vcFrame = %@", NSStringFromCGRect(self.view.frame));
    self.view.backgroundColor = kYellowColor;
    self.title = @"DescVedioViewController";
    //隐藏黑线
   // [super hideNavBlackLine:YES];
  //  super.hj_NavIsHidden = YES;
    [self.view addSubview:self.collectionView];
    //设置状态栏的颜色为黑色
  //  [self setStatusBarBackgroundColor: kBlackColor];
    
}

- (UICollectionView *)collectionView {
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.itemSize = CGSizeMake(kSPScreenWidth, kSPScreenHeight);
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        //最小行间距，默认是有值的
        layout.minimumLineSpacing = 0;
        _collectionView = [[UICollectionView alloc]initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:layout];
        _collectionView.contentSize = CGSizeMake(kSPScreenWidth, kSPScreenHeight * 1);
        _collectionView.backgroundColor = kRedColor;
        _collectionView.pagingEnabled = YES;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        NSLog(@"---collectionViewFrame = %@",NSStringFromCGRect(_collectionView.frame));
        //注册cell
        [_collectionView registerClass:[DescVideoCell class] forCellWithReuseIdentifier:vedioCell];
    }
    return _collectionView;
}

-(void)dealloc {
    NSLog(@"DescVideoViewController - dealloc");
}

#pragma mark - UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}

#pragma mark - UICollectionViewDataSource
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    DescVideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:vedioCell forIndexPath:indexPath];
//    if (!cell) {
//        cell = [[DescVedioCell alloc]init];
//    }
    cell.backgroundColor = kGreenColor;
    cell.mainModel = self.mainModel;
    cell.delegate = self;
   // NSLog(@"***mainModel = %@",self.mainModel);
    NSLog(@"---cellFrame = %@", NSStringFromCGRect(cell.frame));
    return cell;
}


#pragma mark - viewWillAppear
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //隐藏导航栏
    [self.navigationController setNavigationBarHidden:YES animated:NO];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

#pragma mark - DescVedioCellDelegate
//返回按钮的点击
-(void)descVideoCell:(DescVideoCell *)descVideoCell backBtnClicked:(UIButton *)backBtn player:(AVPlayer *)player {
    [self.navigationController popViewControllerAnimated:YES];
    if (player) {
        [player pause];
    }
}


//设置状态栏的样式
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}











/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
